/**
 * 导入改写districExplorer的函数，添加不同功能
 */
// ------------ 功能 ------------------
import addTipmark from "./function/tipMark"
import {addDeClick} from "./function/deClick"
// ------------ 绘制函数 ------------------
import {
    renderAreaNode
} from "./function/renderAreaNode"

let de;

// AMapUI.loadUI(['geo/DistrictExplorer'], function (DistrictExplorer) {
//     de = DistrictExplorer;
// })

export function initDe() {
    AMapUI.loadUI(['geo/DistrictExplorer'], function (DistrictExplorer) {
        de = DistrictExplorer;
    })
}

// -------- 添加DE模块 -----------
export function addDE(adcode, map, that) {
    AMapUI.loadUI(['geo/DistrictExplorer'], function (DistrictExplorer) {
        return initPage(DistrictExplorer, adcode, map, that);
    })
}


// ----------- 启动页面 -------------
function initPage(DistrictExplorer, adcode, map,that) {
    // de对象
    let districtExplorer = new DistrictExplorer({
        eventSupport: true, //打开事件支持
        map,
        zIndex: 8
    });
    // -------- 绘制节点 --------------
    districtExplorer.loadAreaNode(adcode, function (error, areaNode) {
        if (error) {
            console.error(error);
            return;
        }
        renderAreaNode(districtExplorer, areaNode, map);
    });
    addTipmark(districtExplorer, map);
    addDeClick(districtExplorer, adcode, map, that);
    return districtExplorer
}

export function addTip( map) {
    addTipmark(de, map);
}

export function addDeC(adcode, map, that) {
    addDeClick(de, adcode, map, that);
}